package com.kwm.filter;

import com.kwm.entity.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Slf4j
@Component
public class DemoInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String uri = request.getRequestURI();
        if (uri.contains("login")){
            return true;
        }

        String jwt = request.getHeader("token");
        if (jwt == null){
            log.info("令牌为空");
            return false;
        }
        try{
            JwtUtils.parseJWT(jwt);

        }catch (Exception e){
            log.info("错误信息{}",e);
            return false;

        }

        return true;
    }
}
